package com.nvt.core.services;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import oracle.jdbc.OracleTypes;

import com.nvt.core.dao.ISPDAO;
import com.nvt.core.exception.NvtBusinessException;
import com.nvt.core.objectDomain.TxInParameter;

@Service
public class SPServiceImpl implements ISPService {

	@Autowired
	private ISPDAO ispdao;

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.nvt.core.services.ISPService#executeSpCallback()
	 */
	@Override
	public void executeSpCallback(Object[] values) throws NvtBusinessException {
		try {

			TxInParameter[] inParameters = new TxInParameter[2];

			TxInParameter inParameter = new TxInParameter();
			inParameter.setName("p_par_1");
			inParameter.setSqlType(OracleTypes.VARCHAR);
			inParameter.setValue(values[0]);
			inParameters[0] = inParameter;

			inParameter = new TxInParameter();
			inParameter.setName("p_par_2");
			inParameter.setSqlType(OracleTypes.VARCHAR);
			inParameter.setValue(values[1]);
			inParameters[1] = inParameter;

			Map<String, Object> map = new HashMap<String, Object>();
			map.put("inParams", inParameters);
			map.put("spName", "SP_TEST01");

			ispdao.executeSpCallback(map);
		} catch (NvtBusinessException e) {
			throw new NvtBusinessException(e.getMessage());
		}
	}

	public void setIspdao(ISPDAO ispdao) {
		this.ispdao = ispdao;
	}

}
